/*
 * Copyright (c) Facebook, Inc. and its affiliates.
 * All rights reserved.
 *
 * This source code is licensed under the license found in the
 * LICENSE file in the root directory of this source tree.
 */

#import <XCTest/XCTest.h>

#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKCoreKit_Basics/FBSDKCoreKit_Basics.h>

#import "FBSDKLoginKitTests-Swift.h"

#ifdef BUCK
 #import <FBSDKLoginKit+Internal/FBSDKLoginManagerLogger.h>
 #import <FBSDKLoginKit/FBSDKLoginManager.h>
#else
 #import "FBSDKLoginManager.h"
 #import "FBSDKLoginManagerLogger.h"
#endif

@interface FBSDKLoginManagerLoggerTests : XCTestCase
@end

@implementation FBSDKLoginManagerLoggerTests

- (void)setUp
{
  [super setUp];

  [FBSDKSettings.sharedSettings reset];
}

- (void)tearDown
{
  [super tearDown];

  [FBSDKSettings.sharedSettings reset];
}

- (void)testCreatingWithMissingParametersWithTrackingEnabled
{
  XCTAssertNil(
    [FBSDKLoginManagerLogger loggerFromParameters:nil tracking:FBSDKLoginTrackingEnabled],
    "Should not create a logger with missing parameters"
  );
}

- (void)testCreatingWithEmptyParametersWithTrackingEnabled
{
  XCTAssertNil(
    [FBSDKLoginManagerLogger loggerFromParameters:@{} tracking:FBSDKLoginTrackingEnabled],
    "Should not create a logger with empty parameters"
  );
}

- (void)testCreatingWithParametersWithTrackingEnabled
{
  XCTAssertNotNil(
    [FBSDKLoginManagerLogger loggerFromParameters:self.validParameters tracking:FBSDKLoginTrackingEnabled],
    "Should create a logger with valid parameters and tracking enabled"
  );
}

- (void)testCreatingWithMissingParametersWithTrackingLimited
{
  XCTAssertNil(
    [FBSDKLoginManagerLogger loggerFromParameters:nil tracking:FBSDKLoginTrackingLimited],
    "Should not create a logger with limited tracking"
  );
}

- (void)testCreatingWithEmptyParametersWithTrackingLimited
{
  XCTAssertNil(
    [FBSDKLoginManagerLogger loggerFromParameters:@{} tracking:FBSDKLoginTrackingLimited],
    "Should not create a logger with limited tracking"
  );
}

- (void)testCreatingWithParametersWithTrackingLimited
{
  XCTAssertNil(
    [FBSDKLoginManagerLogger loggerFromParameters:self.validParameters tracking:FBSDKLoginTrackingLimited],
    "Should not create a logger with limited tracking"
  );
}

- (void)testInitializingWithMissingLoggingTokenWithTrackingEnabled
{
  XCTAssertNotNil(
    [[FBSDKLoginManagerLogger alloc] initWithLoggingToken:nil
                                                 tracking:FBSDKLoginTrackingEnabled],
    "Shouldn't create a logger with a missing logging token but it will"
  );
}

- (void)testInitializingWithNonStringLoggingTokenWithTrackingEnabled
{
  id token = @{};
  NSString *tokenString = (NSString *)token;

  XCTAssertNotNil(
    [[FBSDKLoginManagerLogger alloc] initWithLoggingToken:tokenString
                                                 tracking:FBSDKLoginTrackingEnabled],
    "Shouldn't create a logger with a non-string logging token but it will"
  );
}

- (void)testInitializingWithLoggingTokenWithTrackingEnabled
{
  XCTAssertNotNil(
    [[FBSDKLoginManagerLogger alloc] initWithLoggingToken:@"123"
                                                 tracking:FBSDKLoginTrackingEnabled],
    "Should create a logger with a logging token"
  );
}

- (void)testInitializingWithMissingLoggingTokenWithTrackingLimited
{
  XCTAssertNil(
    [[FBSDKLoginManagerLogger alloc] initWithLoggingToken:nil
                                                 tracking:FBSDKLoginTrackingLimited],
    "Should not create a logger with limited tracking"
  );
}

- (void)testInitializingWithNonStringLoggingTokenWithTrackingLimited
{
  id token = @{};
  NSString *tokenString = (NSString *)token;

  XCTAssertNil(
    [[FBSDKLoginManagerLogger alloc] initWithLoggingToken:tokenString
                                                 tracking:FBSDKLoginTrackingLimited],
    "Should not create a logger with limited tracking"
  );
}

- (void)testInitializingWithLoggingTokenWithTrackingLimited
{
  XCTAssertNil(
    [[FBSDKLoginManagerLogger alloc] initWithLoggingToken:@"123"
                                                 tracking:FBSDKLoginTrackingLimited],
    "Should not create a logger with limited tracking"
  );
}

- (NSDictionary<NSString *, id> *)validParameters
{
  return @{@"state" : @"{\"challenge\":\"ibUuyvhzJW36TvC7BBYpasPHrXk%3D\",\"0_auth_logger_id\":\"A48F8D79-F2DF-4E04-B893-B29879A9A37B\",\"com.facebook.sdk_client_state\":true,\"3_method\":\"sfvc_auth\"}"};
}

@end
